﻿using System.IO.IsolatedStorage;
using System.ComponentModel;

namespace CuteRibs.MVVMLib
{
	public class Settings
	{
		public static T GetSettingValue<T>(string settingName, T defaultValue = default(T))
		{
			object value = GetSettingValue(settingName);
			return value == null ? defaultValue : (T)value;
		}

		public static object GetSettingValue(string settingName)
		{
			if (!DesignerProperties.IsInDesignTool)
			{
				if (IsolatedStorageSettings.ApplicationSettings.Contains(settingName))
				{
					return IsolatedStorageSettings.ApplicationSettings[settingName];
				}
			}

			return null;
		}

		public static void SetSettingValue(string settingName, object value)
		{
			if (!DesignerProperties.IsInDesignTool)
			{
				IsolatedStorageSettings.ApplicationSettings[settingName] = value;
				//IsolatedStorageSettings.ApplicationSettings.Save();
			}
		}
	}
}
